package cn.edu.hubu.hubuhotel.service.impl;

import cn.edu.hubu.hubuhotel.entity.Reserve;
import cn.edu.hubu.hubuhotel.mapper.ReserveMapper;
import cn.edu.hubu.hubuhotel.service.ReserveService;
import cn.edu.hubu.hubuhotel.vo.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ReserveServiceImpl implements ReserveService {
    @Autowired
    private ReserveMapper reserveMapper;

    @Override
    public ResultVO loginByaccountandpwd(String account,String pwd){
        List<Reserve> reserves = reserveMapper.selectByAandP(account, pwd);
        if(reserves != null){
            return new ResultVO(200,"登录成功",reserves);
        }else{
            return new ResultVO(500,"账号密码输入错误",null);
        }
    }

    @Override
    public ResultVO insertReserve(Reserve reserve){
        int newreserve = reserveMapper.insertReserve(reserve);
        if(newreserve > 0){
            return new ResultVO(200,"预定成功",newreserve);
        }else{
            return new ResultVO(500,"预定失败",null);
        }
    }

    @Override
    public ResultVO deleteReserve(int userId,int roomId){
        int deletereserve = reserveMapper.deleteReserve(userId,roomId);
        if(deletereserve > 0){
            return new ResultVO(200,"删除成功",null);
        }else{
            return new ResultVO(500,"删除失败",null);
        }
    }

    @Override
    public ResultVO selectByUserId(int userId){
        List<Reserve> reserves = reserveMapper.selectByUserId(userId);
        if(reserves != null){
            return new ResultVO(200,"查询成功",reserves);
        }else{
            return new ResultVO(500,"无信息",null);
        }
    }
}
